package com.ruoyi.warehouse.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warehouse.domain.DrugWarehouse;
import com.ruoyi.warehouse.service.IDrugWarehouseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药库Controller
 * 
 * @author ruoyi
 * @date 2025-08-22
 */
@RestController
@RequestMapping("/warehouse/drug_warehouse")
public class DrugWarehouseController extends BaseController
{
    @Autowired
    private IDrugWarehouseService drugWarehouseService;

    /**
     * 查询药库列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drug_warehouse:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugWarehouse drugWarehouse)
    {
        startPage();
        List<DrugWarehouse> list = drugWarehouseService.selectDrugWarehouseList(drugWarehouse);
        return getDataTable(list);
    }

    /**
     * 导出药库列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drug_warehouse:export')")
    @Log(title = "药库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugWarehouse drugWarehouse)
    {
        List<DrugWarehouse> list = drugWarehouseService.selectDrugWarehouseList(drugWarehouse);
        ExcelUtil<DrugWarehouse> util = new ExcelUtil<DrugWarehouse>(DrugWarehouse.class);
        util.exportExcel(response, list, "药库数据");
    }

    /**
     * 获取药库详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drug_warehouse:query')")
    @GetMapping(value = "/{warehouseId}")
    public AjaxResult getInfo(@PathVariable("warehouseId") Long warehouseId)
    {
        return success(drugWarehouseService.selectDrugWarehouseByWarehouseId(warehouseId));
    }

    /**
     * 新增药库
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drug_warehouse:add')")
    @Log(title = "药库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugWarehouse drugWarehouse)
    {
        return toAjax(drugWarehouseService.insertDrugWarehouse(drugWarehouse));
    }

    /**
     * 修改药库
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drug_warehouse:edit')")
    @Log(title = "药库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugWarehouse drugWarehouse)
    {
        return toAjax(drugWarehouseService.updateDrugWarehouse(drugWarehouse));
    }

    /**
     * 删除药库
     */
    @PreAuthorize("@ss.hasPermi('warehouse:drug_warehouse:remove')")
    @Log(title = "药库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{warehouseIds}")
    public AjaxResult remove(@PathVariable Long[] warehouseIds)
    {
        return toAjax(drugWarehouseService.deleteDrugWarehouseByWarehouseIds(warehouseIds));
    }
}
